package com.group.three.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.three.mapper.CommentMapper;
import com.group.three.pojo.Comment;
import com.group.three.service.CommentService;
import com.group.three.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<Comment> selectCommentAll() {
        return commentMapper.selectCommentAll();
    }

    @Override
    public int deleteComment(Long commentId) {
        return commentMapper.deleteComment(commentId);
    }

    //分页功能
    @Override
    public PageInfo<Comment> getCommentAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        //调用主查询，配合分页功能实现分页
        List<Comment> comments = commentMapper.selectCommentAll();
        //分页插件对分页结果进行的封装，里面包含上下页，当前页码，数据集等等数据
        PageInfo<Comment> pageInfo = new PageInfo<Comment>(comments, pageNum);
        return pageInfo;
    }

    @Override
    public PageInfo<Comment> selectCommentKeyWordList(String keyWord, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        //调用主查询，配合分页功能实现分页
        List<Comment> comments = commentMapper.selectCommentKeyWord(keyWord);
        //分页插件对分页结果进行的封装，里面包含上下页，当前页码，数据集等等数据
        PageInfo<Comment> pageInfo = new PageInfo<Comment>(comments, pageNum);
        return pageInfo;
    }

    @Override
    public int insertComment(Long commentId,Long personId, String commentContent, String movieName, String addTime) {
        return commentMapper.insertComment(commentId,personId, commentContent, movieName, addTime);
    }

    //主页留言下方的分页
    @Override
    public PageInfo<Comment> selectHomeCommentList(String movieName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        //调用主查询，配合分页功能实现分页
        List<Comment> comments = commentMapper.selectHomeComment(movieName);
        //分页插件对分页结果进行的封装，里面包含上下页，当前页码，数据集等等数据
        PageInfo<Comment> pageInfo = new PageInfo<Comment>(comments, pageNum);
        return pageInfo;
    }

    @Override
    public List<Comment> selectAdminComment(String personName) {
        return commentMapper.selectAdminComment(personName);
    }

    @Override
    public PageInfo<Comment> selectAdminCommentList(String personName,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        //调用主查询，配合分页功能实现分页
        List<Comment> adminComment = commentMapper.selectAdminComment(personName);
        //分页插件对分页结果进行的封装，里面包含上下页，当前页码，数据集等等数据
        PageInfo<Comment> pageInfo = new PageInfo<Comment>(adminComment, pageNum);
        return pageInfo;
    }

    @Override
    public int updateAdminComment(Long movieId, Integer videoComments) {
        return commentMapper.updateAdminComment(movieId,videoComments);
    }
}
